The argument values areint pfxpoll(dev_t dev, short events, int anyyet, short *reventsp, struct pollhead **phpp);
dev | A dev_t value from which you can extract the major and minor device numbers. |
events | Bit-flags for the events the user process is testing, as passed to poll() and declared in sys/poll.h.. |
reventsp | A field to receive the bit-flags of events that have occurred, or to receive 0x0000 if no requested events have occurred.. |
anyyet and phpp | When anyyet is nonzero and no events have occurred, the kernel requires the address of the pollhead structure for this minor device to be returned in *phpp. |
Example 8-2 shows the pfxpoll() code of a hypothetical device driver. Only three event tests are supported: POLLIN and POLLRDNORM (treated as equivalent) and POLLOUT. The device driver maintains an array of pollhead structures, one for each supported minor device. These are presumably allocated during initialization.
Example 8-2 : pfxpoll() Code for Hypothetical Driver
struct pollhead phds[MAXMINORS]; #define OUR_EVENTS (POLLIN|POLLOUT|POLLRDNORM) hypo_poll(dev_t dev, short events, int anyyet, short *reventsp, struct pollhead **phpp) { minor_t dminor = geteminor(dev); short happened = 0; short wanted = events & OUR_EVENTS; if (wanted & (POLLIN|POLLRDNORM)) { if (device_has_data_ready(dminor)) happened |= (POLLIN|POLLRDNORM); } if (wanted & POLLOUT) { if (device_ready_for_output(dminor)) happened |= POLLOUT; } if (device_pending_error(dminor)) happened |= POLLERR; if (0 == (*reventsp = happened)) { if (anyyet) *phpp = phds[dminor] } return 0; }The code in Example 8-2 begins by discarding any unsupported event flags that might have been requested. Then it tests the remaining flags against the device status. If the device has an uncleared error, the code inserts the POLLERR event. If no events were detected, and if the kernel requested it, the address of the pollhead structure for this minor device is returned.